/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.maze.configuration;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.maze.display.IDisplay;

/**
 *
 * @author tpasquie
 */
public class TestConfiguration {
    private static final String POPULATION_TAG ="Population";
    private static final String DISPLAY_TAG ="Display";

    private Document document = null;
    private ArrayList<PopulationConfiguration> configs=new ArrayList<PopulationConfiguration>();
    private IDisplay display=null;

    public TestConfiguration(String path) throws Exception{
        SAXBuilder sxb = new SAXBuilder();
        document = sxb.build(new File(path));
        Class t = Class.forName(document.getRootElement().getChildText(DISPLAY_TAG).trim());
        display = (IDisplay)t.getConstructor().newInstance();
        List populations = document.getRootElement().getChildren(POPULATION_TAG);
        for(Object o : populations ){
            Element e =(Element)o;
            configs.add(new PopulationConfiguration(e));
        }
    }

    public ArrayList<PopulationConfiguration> getConfigurations(){
        return configs;
    }

    public IDisplay getDisplay(){
        return display;
    }
}
